home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / General / MM3Tp.sea Folder / Made by Marksman / Sources / mm / mmMD_My_Movable_Moda.p < prev    next >
Text File  |  1994-01-16  |  11KB  |  296 lines

  1.  
  2. Unit mmMD_My_Movable_Moda;
  3. {  mmMD_My_Movable_Moda                                 Handle this dialog }
  4. {  Copyright © 1994 George R. Cossey }
  5.  
  6. {    File name:  mmMD_My_Movable_Moda
  7.     Function:  Handle this modeless dialog.
  8.  
  9.     This dialog is called when:
  10.  
  11.     History: 1/16/94 Original by George Cossey
  12.  
  13. }
  14.  
  15. { ======================================================= }
  16. { ======================================================= }
  17.  
  18. interface
  19.  
  20.     uses
  21.         Printing,Folders,Sound,mmCommonMM_Demo,CommonMM_Demo,
  22.         mmPA_My_Alert,
  23.         {}
  24.         mmD_My_Modal,
  25.         {}
  26.         UMy_Movable_Moda;
  27.  
  28.  
  29. procedure Init_My_Movable_Moda;
  30. procedure Moved_My_Movable_Moda(OldRect:Rect;theWindow:WindowPtr);    { Moved this window }
  31. procedure Update_My_Movable_Moda(theWindow:WindowPtr);
  32. procedure Open_My_Movable_Moda;
  33. procedure Close_My_Movable_Moda(theWindow:WindowPtr);
  34. procedure Do_My_Movable_Moda(var theEvent:EventRecord;theWindow:WindowPtr;itemHit:integer);
  35.  
  36. { ======================================================= }
  37. { ======================================================= }
  38.  
  39. implementation
  40.  
  41. { ======================================================= }
  42. { ======================================================= }
  43.  
  44. { Routine: Init_My_Movable_Moda }
  45. { Purpose: This procedures purpose is to set the window pointer to nil, }
  46. { this is used to tell the other routines }
  47.  
  48. procedure Init_My_Movable_Moda;
  49. var
  50.     tempRect:Rect;                                    { Temporary rectangle }
  51.     DType:integer;                                    { Type of dialog item }
  52.     Index:integer;                                    { For looping }
  53.     DItem:Handle;                                    { Handle to the dialog item }
  54.     CItem, CTempItem:ControlHandle;                    { Control handle }
  55.     sTemp:Str255;                                    { Get text entered, temp holding }
  56.     itemHit:integer;                                { Get selection }
  57.     temp:integer;                                    { Get selection, temp holding }
  58.  
  59.  
  60. begin
  61. Rec_My_Movable_Moda.theDialog := nil;                    { Initialize to say that the dialog is not yet active }
  62.  
  63. Rec_My_Movable_Moda.Enable_OK4 := true;            { Button }
  64. Rec_My_Movable_Moda.Enable_Cancel3 := true;            { Button }
  65. Rec_My_Movable_Moda.List_List_of_things := nil;                            { List }
  66. SetRect(Rec_My_Movable_Moda.ListRect_List_of_things,15,10,285,125);        { left,top,right,bottom }
  67.  
  68. U_Init_My_Movable_Moda;                            { Call the user init routine }
  69. end;
  70.  
  71. { ======================================================= }
  72.  
  73. { Routine: Moved_My_Movable_Moda }
  74. { Purpose: We were moved, possibly to another screen and screen depth }
  75.  
  76. procedure Moved_My_Movable_Moda(OldRect:Rect;theWindow:WindowPtr);    { Moved this window }
  77. var
  78.     SavePort:WindowPtr;                                { Place to save the last port }
  79.  
  80.  
  81. begin
  82. if (Rec_My_Movable_Moda.theDialog = theWindow)    then            { Only do if the window is us }
  83.     begin
  84.     GetPort(SavePort);                            { Save the current port }
  85.     SetPort(theWindow);                            { Set the port to my window }
  86.  
  87.     U_Moved_My_Movable_Moda(theWindow,OldRect);    { Call user routine when we are moved }
  88.     SetPort(SavePort);                                { Restore the old port }
  89.     end;                                            { End of IF }
  90. end;
  91.  
  92. { ======================================================= }
  93.  
  94. { Routine: Update_My_Movable_Moda }
  95. { Purpose: This procedures purpose is to refresh this window, update it, }
  96. { when we are uncovered by another window.  }
  97.  
  98. procedure Update_My_Movable_Moda(theWindow:WindowPtr);
  99. var
  100.     SavedPort:GrafPtr;                                { Save the current port so we can restore to it }
  101.     tempRect:Rect;                                    { Temporary rectangle variable }
  102.     rTempRect:Rect;                                    { Temporary rectangle variable }
  103.     DType:integer;                                    { Type of dialog item }
  104.     DItem:Handle;                                    { Handle to the dialog item }
  105.     CItem:ControlHandle;                            { Control handle }
  106.     Saved_ForeColor:RGBColor;                        { Place to save colors }
  107.     Saved_BackColor:RGBColor;                        { Place to save colors }
  108.     DrawingColor:RGBColor;                            { Place to make colors }
  109.  
  110.  
  111. begin
  112. if ((Rec_My_Movable_Moda.theDialog <> nil) and (theWindow = Rec_My_Movable_Moda.theDialog)) then{ Only do if we are the window to update }
  113.     begin
  114.     GetPort(SavedPort);                            { Get the current port }
  115.     SetPort(theWindow);                            { Point to our port for drawing in our window }
  116.     if (Has.ColorQD) then                                { See if color QuickDraw is around }
  117.         begin
  118.         GetForeColor(Saved_ForeColor);            { Save the fore color }
  119.         GetBackColor(Saved_BackColor);            { Save the back color }
  120.  
  121.         RGBForeColor(Black_ForeColor);            { Set the fore color to Black }
  122.         RGBBackColor(White_BackColor);            { Set the back color to White }
  123.         end;                                        { End of IF }
  124.  
  125.     { This is the default selection, when RETURN is pressed. }
  126.     HiliteDefaultButton(theWindow,ResD_OK4);
  127.  
  128.     UpdateTheList(theWindow^.visRgn,Rec_My_Movable_Moda.List_List_of_things,Rec_My_Movable_Moda.ListRect_List_of_things,
  129.         12,systemFont,[],true);
  130.  
  131.     TextSize(12);
  132.     TextFont(systemFont);                                { Select the Font that we want }
  133.     TextFace([]);                                        { Select the style that we want }
  134.  
  135.     if (Has.ColorQD) then                                { See if color QuickDraw is around }
  136.         begin
  137.         RGBForeColor(Saved_ForeColor);            { Restore the fore color }
  138.         RGBBackColor(Saved_BackColor);            { Restore the back color }
  139.         end;
  140.  
  141.     U_Update_My_Movable_Moda(theWindow);            { Call the user update routine }
  142.  
  143.     DrawDialog(theWindow);                            { Draw the rest of the controls }
  144.     SetPort(SavedPort);                            { Restore the port that we saved at the start }
  145.     end;
  146. end;
  147.  
  148. { ======================================================= }
  149.  
  150. { Routine: Open_My_Movable_Moda }
  151. { Purpose: This procedures purpose is to open this window and set all }
  152. { of the initial conditions, such as default edit text. }
  153.  
  154. procedure Open_My_Movable_Moda;
  155. var
  156.     ThisEditText:TEHandle; 
  157.     TheDialogPtr:DialogPeek;
  158.     tempRect:Rect;                                { Temporary rectangle variable }
  159.     DType:integer;                                { Type of dialog item }
  160.     DItem:Handle;                                { Handle to the dialog item }
  161.     CItem:ControlHandle;                        { Control handle }
  162.     LTemp,LTemp2,theLong:longint;                { Get selection, temp holding }
  163.  
  164.  
  165. begin
  166. if (Rec_My_Movable_Moda.theDialog = NIL) then
  167.     begin
  168.     Rec_My_Movable_Moda.theDialog := GetNewDialog(ResD_My_Movable_Moda,NIL,WindowPtr(-1));{ Bring in the dialog resource }
  169.     SetPort(Rec_My_Movable_Moda.theDialog);        { Prepare to add conditional text }
  170.  
  171.  
  172.  
  173.     Doing_MovableModal := true;
  174.     
  175.     { Button }
  176.     SetupNormalControl(Rec_My_Movable_Moda.theDialog,ResD_OK4,Rec_My_Movable_Moda.Enable_OK4,0);
  177.  
  178.     { Button }
  179.     SetupNormalControl(Rec_My_Movable_Moda.theDialog,ResD_Cancel3,Rec_My_Movable_Moda.Enable_Cancel3,0);
  180.  
  181.     { Make a List }
  182.     Make_A_List(Rec_My_Movable_Moda.List_List_of_things,Rec_My_Movable_Moda.ListRect_List_of_things,
  183.         Rec_My_Movable_Moda.theDialog,sResD_List_of_things,12,systemFont,[],true);
  184.  
  185.  
  186.  
  187.     U_Setup_My_Movable_Moda(Rec_My_Movable_Moda.theDialog);{ Call the user Open procedure }
  188.  
  189.     ShowWindow(Rec_My_Movable_Moda.theDialog);                { Open a dialog box }
  190.     SelectWindow(Rec_My_Movable_Moda.theDialog);            { Lets see it }
  191.     end
  192. else
  193.     SelectWindow(Rec_My_Movable_Moda.theDialog);        { Lets see it }
  194. end;
  195.  
  196. { ======================================================= }
  197.  
  198. { Routine: Close_My_Movable_Moda }
  199. { Purpose: This procedures purpose is to close this window and clear }
  200. { the window pointer variable }
  201.  
  202. procedure Close_My_Movable_Moda(theWindow:WindowPtr);
  203. var
  204.     tempRect:Rect;                                    { Temporary rectangle }
  205.     DType:integer;                                    { Type of dialog item }
  206.     DItem:Handle;                                    { Handle to the dialog item }
  207.  
  208.  
  209. begin
  210. if ((Rec_My_Movable_Moda.theDialog <> NIL) and (theWindow = Rec_My_Movable_Moda.theDialog)) then{ Only close if it is us and we were open }
  211.     begin
  212.     U_Close_My_Movable_Moda(theWindow);            { Call the user close routine }
  213.  
  214.  
  215.     Doing_MovableModal := false;
  216.     
  217.     DisposDialog(theWindow);                        { Close on the screen and Flush the dialog out of memory }
  218.     Rec_My_Movable_Moda.theDialog := nil;            { Make sure our other routines know that we are closed }
  219.     end;
  220. end;
  221.  
  222. { ======================================================= }
  223.  
  224. { Routine: Do_My_Movable_Moda }
  225. { Purpose: This procedures purpose is to handle all actions, such as buttons being pressed. }
  226. { This is the real meat of this unit and is where the code is for acting upon the users actions. }
  227.  
  228. procedure Do_My_Movable_Moda(var theEvent:EventRecord;theWindow:WindowPtr;itemHit:integer);
  229. var
  230.     Index:integer;                                        { For looping }
  231.     myPt:Point;                                            { For the local mouse position }
  232.     DType:integer;                                        { Type of dialog item }
  233.     DItem:Handle;                                        { Handle to the dialog item }
  234.     tempRect:Rect;                                        { Temporary rectangle }
  235.     CItem:ControlHandle;                                { Control handle }
  236.     temp:integer;                                        { temp integer }
  237.     code:integer;                                        { temp integer }
  238.     theSelection:integer;                                { For Palettes }
  239.     DoubleClick:Boolean;                                { For sensing double clicks in a list }
  240.  
  241.  
  242. begin
  243. Rec_My_Movable_Moda.ExitDialog := false;            { Do not close the dialog yet }
  244. if ((theEvent.what = mouseDown) and (Rec_My_Movable_Moda.theDialog <> nil)) then
  245.     begin
  246.     SetPort(Rec_My_Movable_Moda.theDialog);                    { Set the port to our dialog }
  247.     myPt := theEvent.where;                            { Get the position where the mouse was pressed }
  248.     GlobalToLocal(myPt);                            { Change from global to local location }
  249.  
  250.     if (PtInRect(myPt,Rec_My_Movable_Moda.ListRect_List_of_things)) then
  251.         ClickInTheList(myPt,theEvent.modifiers,Rec_My_Movable_Moda.List_List_of_things,12,systemFont,[],true);
  252.  
  253.     end;
  254.  
  255. if ((Rec_My_Movable_Moda.theDialog <> nil) and (Rec_My_Movable_Moda.theDialog = theWindow)) then
  256.     begin
  257.     CheckKeysInDialog(theWindow,DoubleClick,theEvent,itemHit);
  258.  
  259.     myPt := theEvent.where;                            { Get the position where the mouse was pressed }
  260.     GlobalToLocal(myPt);                            { Change from global to local location }
  261.  
  262.     U_Hit_My_Movable_Moda(theWindow,itemHit,Rec_My_Movable_Moda.ExitDialog,theEvent);{ Give the user the itemhit }
  263.  
  264.     if (itemHit > 0) then                                { Skip if user set to zero }
  265.         begin
  266.         GetDItem(theWindow,itemHit,DType,DItem,tempRect);{ Get which item was pressed }
  267.         CItem := ControlHandle(DItem);                { Change the pointer for getting to the control }
  268.         end;
  269.     
  270.     { Handle it real time }
  271.     if (itemHit = ResD_OK4) then                { Handle the Button being pressed }
  272.         begin
  273.         Add_UserEvent(UserEvent_Close_Window,ResD_My_Movable_Moda,0,0,nil);    { Close this modeless dialog }
  274.         Rec_My_Movable_Moda.ExitDialog := true;        { Close this dialog, exit }
  275.         end;
  276.  
  277.     if (itemHit = ResD_Cancel3) then                { Handle the Button being pressed }
  278.         begin
  279.         Add_UserEvent(UserEvent_Close_Window,ResD_My_Movable_Moda,0,0,nil);    { Close this modeless dialog }
  280.         Rec_My_Movable_Moda.ExitDialog := true;        { Close this dialog, exit }
  281.         end;
  282.  
  283.  
  284.     end;
  285.  
  286. if (Rec_My_Movable_Moda.ExitDialog) then                { Do the close of the dialog }
  287.     begin
  288.     Close_My_Movable_Moda(Rec_My_Movable_Moda.theDialog);
  289.     Rec_My_Movable_Moda.theDialog := nil;                    { Clear it for future checks }
  290.     end;
  291. end;
  292.  
  293. { ======================================================= }
  294. { ======================================================= }
  295. end.
  296.